#!/bin/sh

. ../../func

URL=https://www.kernel.org/pub/linux/utils/util-linux/v2.22
SRC=util-linux
PKG=util-linux-222_static
VER=2.22.2
COMP=tar.xz
DESC=""
DEPS=
CAT=BuildingBlock
CWD=`pwd`

build() {
	cp -f ../config.sub ${SRC}-${VER}/config
	cd ${SRC}-${VER}
	patch -p1 < ../util-linux-222.patch
	opts="--prefix=/usr --enable-static-programs=losetup
--disable-shared --disable-nls --without-ncurses --disable-libuuid --disable-libblkid
--disable-libmount --disable-mount --disable-fsck --disable-partx
--disable-uuidd --disable-mountpoint --disable-fallocate
--disable-eject --disable-agetty
--disable-cramfs --disable-switch_root --disable-pivot_root
--disable-kill --disable-utmpdump --disable-raw --disable-rename
--disable-chsh-only-listed --disable-login --disable-sulogin --disable-su
--disable-schedutils --disable-wall
--disable-pg-bell --disable-use-tty-group --disable-makeinstall-chown
--disable-makeinstall-setuid --without-selinux "
	_configure
	sed -i 's|^LDFLAGS =.*|LDFLAGS = -all-static|' Makefile
	_make ${MKFLG} losetup
	abort_if_file_not_found losetup
	install -d -m 0755 $CWD/${PKG}-${VER}-${ARCH}/bin
	mv losetup losetup-222
	_install losetup-222 $CWD/${PKG}-${VER}-${ARCH}/bin
	cd -
}

package() {
	# add this recipe
	install -d -m 0755 ./${PKG}-${VER}-${ARCH}/build
	cat ${PKG}.petbuild > ./${PKG}-${VER}-${ARCH}/build/$PKG-build-recipe
	# move, don't package
	cp -a --remove-destination ./${PKG}-${VER}-${ARCH}/* ../../00_${ARCH}
	rm -r ${SRC}-${VER}
	rm -r ${PKG}-${VER}-${ARCH}
	echo "moved to initrd"
	echo "done!"
}

# main
retrieve ${SRC}-${VER}.${COMP}
[ "$DLD_ONLY" = "yes" ] && exit
extract ${SRC}-${VER}.${COMP}
build
package
